<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="分组" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="groupName">
              <a-input v-model="model.groupName" placeholder="请输入分组"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="负责人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="storeMamager">
              <j-select-user-by-dep v-model="model.storeMamager" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="店铺名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shopName">
              <a-input v-model="model.shopName" placeholder="请输入店铺名称"  ></a-input>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="12">-->
<!--            <a-form-model-item label="站点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="site">-->
<!--              <j-single-select-tag type="list_multi" v-model="model.site" dictCode="finance_amazon_site" placeholder="请选择站点" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="12">
            <a-form-model-item label="国家" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="countryCode">
              <j-single-select-tag type="list_multi" v-model="model.countryCode" dictCode="lg_finance_amazon_country,country_name,country_code" placeholder="请选择国家" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="平台结算时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dateWarehouseShipping">
              <a-input v-model="model.dateWarehouseShipping" placeholder="请输入平台结算时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
              <a-input v-model="model.type" placeholder="请输入类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="sku" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sku">
              <a-input v-model="model.sku" placeholder="请输入sku"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description">
              <a-input v-model="model.description" placeholder="请输入描述"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="店铺单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="saleOrderCode">
              <a-input v-model="model.saleOrderCode" placeholder="请输入店铺单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quantity">
              <a-input v-model="model.quantity" placeholder="请输入数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="产品金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productAmount">
              <a-input-number v-model="model.productAmount" placeholder="请输入产品金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="产品金额税费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productAmountTax">
              <a-input-number v-model="model.productAmountTax" placeholder="请输入产品金额税费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="客户运费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerFreight">
              <a-input-number v-model="model.customerFreight" placeholder="请输入客户运费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="客户运费税费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerFreightTax">
              <a-input-number v-model="model.customerFreightTax" placeholder="请输入客户运费税费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="买家支付的礼品包装费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="giftFee">
              <a-input-number v-model="model.giftFee" placeholder="请输入买家支付的礼品包装费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="买家支付的礼品包装费税费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="giftFeeTax">
              <a-input-number v-model="model.giftFeeTax" placeholder="请输入买家支付的礼品包装费税费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="亚马逊积分费用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amazonIntegralFee">
              <a-input-number v-model="model.amazonIntegralFee" placeholder="请输入亚马逊积分费用" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="折扣促销" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="discount">
              <a-input-number v-model="model.discount" placeholder="请输入折扣促销" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="折扣促销税费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="discountTax">
              <a-input-number v-model="model.discountTax" placeholder="请输入折扣促销税费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="亚马逊税费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amazonTax">
              <a-input-number v-model="model.amazonTax" placeholder="请输入亚马逊税费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="平台手续费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="platformFee">
              <a-input-number v-model="model.platformFee" placeholder="请输入平台手续费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="FBA手续费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fbaFee">
              <a-input-number v-model="model.fbaFee" placeholder="请输入FBA手续费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="其他交易费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="otherFee">
              <a-input-number v-model="model.otherFee" placeholder="请输入其他交易费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="其他" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="other">
              <a-input-number v-model="model.other" placeholder="请输入其他" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="总共" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="total">
              <a-input-number v-model="model.total" placeholder="请输入总共" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'FinanceAmazonOrderForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/amazon/financeAmazonOrder/add",
          edit: "/amazon/financeAmazonOrder/edit",
          queryById: "/amazon/financeAmazonOrder/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>